package com.baijiaoxi.common.model.excel;

import com.baijiaoxi.common.utils.jdk.Strings;

import java.util.List;

/**
 * 通过表头获取对应的字段名
 */
public interface ExcelHeaderAnalyser {
    //适合根据标题直接确定赋值字段，且最好实体对象实现了FieldAccessibleByNameModel的情况
    default String getFieldNameByExcelHeader(int headerIndex, String headerTitle) {
        return null;
    }

    default HeaderCellInfo getHeaderCellInfo(int headerIndex, String headerTitle) {
        String fieldName = getFieldNameByExcelHeader(headerIndex, headerTitle);
        if (Strings.isNullOrEmpty(fieldName))
            return null;
        HeaderCellInfo headerCellInfo = new HeaderCellInfo(headerIndex, headerTitle);
        headerCellInfo.setFieldName(fieldName);
        return headerCellInfo;
    }

    default void afterAnalyseHeader(List<HeaderCellInfo> headerCellInfoList) {
    }
}
